<template>
	<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
			
		  <el-form-item label="商品编号" prop="gno">
			<el-input v-model="ruleForm.gno" ></el-input>
		  </el-form-item>
		  <el-form-item label="商品名称" prop="gname">
			<el-input v-model="ruleForm.gname"></el-input>
		  </el-form-item>
		  <el-form-item label="商品单价" prop="gprice">
			<el-input v-model="ruleForm.gprice"></el-input>
		  </el-form-item>
		  <el-form-item label="供应商编号" prop="sno">
			<el-input v-model="ruleForm.sno"></el-input>
		  </el-form-item>
		  <el-form-item label="商品简介" prop="ginfo">
			<el-input v-model="ruleForm.ginfo"></el-input>
		  </el-form-item>
		  <el-form-item label="备注" prop="gremark">
			<el-input v-model="ruleForm.gremark"></el-input>
		  </el-form-item>
		  
	
		  <el-form-item>
			<el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
			 <el-button @click="resetForm('ruleForm')">重置</el-button>
		  </el-form-item>
	</el-form>
</template>

<script>
  export default {
	  name: "GoodsUpdate",
			data() {
			  return {
				ruleForm: {
				  gno:'',
				  gname:'',
				  gprice:'',
				  sno:'',
				  ginfo:'',
				  gremark:'' 
				},
				rules: {
						
				}
			  };
			},
			methods: {
			 submitForm(formName) {
				 const _this = this;
			         this.$refs[formName].validate((valid) => {
			           if (valid) {
							axios.put('http://localhost:8181/goods/update',this.ruleForm).then(function(resp){
								console.log(resp)
								if(resp.data == 'success'){
									_this.$message('添加成功！');
									_this.$router.push('/GoodsSearch')
								}
							})
			           } else {
			             console.log('error submit!!');
			             return false;
			           }
			         });
			       },
			       resetForm(formName) {
			         this.$refs[formName].resetFields();
			       }
			     },
				 created(){
				 					const _this = this;
				 					 axios.get('http://localhost:8181/goods/findById/'+this.$route.query.id).then(function(resp){
				 						_this.ruleForm = resp.data
				 					 })
				 }
		  }
</script>